New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

css-strip-units

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-strip-units

Strip everything but the unit from a CSS value.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
74
decreased by-36.21%
Maintainers
1
Weekly downloads
 
Created
Source

css-strip-units NPM version Build Status

Strip everything but the unit from a CSS value.

strip('1px')
// => 'px'

strip('30.5kHz')
// => 'kHz'

strip(['100%', '99rem', '.25s'])
// => ['%', 'rem', 's']

This module stays future-proof by stripping numbers off the front, so non-existent units are still passed with this module. Use another module to check the validity of units.

To get the number of a CSS value simply use parseFloat or parseInt (it actually works!):

var value = '100px'

// User css-strip-units to get unit:
var unit = strip(value)
// => 'px'

// Use parseFloat to get number:
var number = parseFloat(value)
// => 100

Installation

$ npm install --save css-strip-units

API

strip(value)

Strip any number's unit (including those non-existent).

  • value (String|Array): String or array of values to strip the unit(s) from.
strip('2px')
// => '2'

strip(['.01px', '9px'])
// => ['.01', '9']

Returns string or array depending the type of value you input.

License

MIT © Jamen Marz

Keywords

FAQs

Package last updated on 18 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc